package com.zte.purchase.control;


import com.zte.purchase.model.CType;
import com.zte.purchase.model.CTypeCondition;
import com.zte.purchase.server.IProductTypeService;
import com.zte.util.OperatorLog;
import com.zte.util.PageModel;
import com.zte.util.ResultMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class ProductTypeAction {

    @Autowired
    private IProductTypeService typeService;

    @RequestMapping("/productType/addProductType")
//    @OperatorLog(operate="添加产品类型", module="采购管理")
    @ResponseBody
    public ResultMessage addProductType(CType addCType){
        boolean isAdd = typeService.addProductType(addCType);

        ResultMessage msg = new ResultMessage();
        msg.setStatus(200);
        msg.setMsg("查询成功");
        msg.setFlag(true);
        msg.setData(isAdd);

        return msg;
    }

    @RequestMapping("/productType/updateCType")
//    @OperatorLog(operate="修改产品类型", module="采购管理")
    @ResponseBody
    public ResultMessage UpdateCType(CType updateCType){
        boolean isUpdate = typeService.updateCType(updateCType);

        ResultMessage msg = new ResultMessage();
        msg.setStatus(200);
        msg.setMsg("查询成功");
        msg.setFlag(true);
        msg.setData(isUpdate);

        return msg;
    }

    @RequestMapping("/productType/findOneCType")
    @ResponseBody
    public ResultMessage FindOneCType(String typeId){

        CType oneCType = typeService.findOneCType(typeId);

        ResultMessage msg = new ResultMessage();
        msg.setStatus(200);
        msg.setMsg("查询成功");
        msg.setFlag(true);
        msg.setData(oneCType);

        return msg;
    }

    @RequestMapping("/productType/queryTypePage")
//    @OperatorLog(operate="多条件分页查询产品类型", module="采购管理")
    @ResponseBody
    public ResultMessage queryTypePage(Integer pageNum, Integer pageSize, CTypeCondition ctConn){
        PageModel<CType> pageModel = new PageModel<>();
        pageModel.setPageNum(pageNum);
        pageModel.setPageSize(pageSize);

        PageModel<CType> mo = typeService.queryTypeList(pageModel, ctConn);

        ResultMessage msg = new ResultMessage();
        msg.setStatus(200);
        msg.setMsg("查询成功");
        msg.setFlag(true);
        msg.setData(mo);

        return msg;
    }

}
